package com.changgou.web.gateway.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.http.HttpCookie;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.stereotype.Service;
import org.springframework.util.MultiValueMap;

/**
 * @Author: HuangFu
 * @Date: 2020/2/11 11:08
 * @Description:  认证服务
 */
@Service
public class AuthService {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    /**
     * 获取Cookie的数据
     * @param request
     * @param key
     * @return
     */
    public String getCookieValue(ServerHttpRequest request,String key){
        MultiValueMap<String, HttpCookie> cookies = request.getCookies();
        HttpCookie cookie = cookies.getFirst(key);
        if(cookie == null){
            return null;
        }
        return cookie.getValue();
    }

    /**
     * 获取token 根据jtl
     * @param jtl
     * @return
     */
    public String getJwtToken(String jtl){
        return stringRedisTemplate.boundValueOps(jtl).get();
    }



}
